<template>
    <div class="box">
     
      <div class="login-box">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
          label-position="top"
          
        >
          <el-form-item label="账号" prop="account">
            <el-input v-model="ruleForm.account" ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="ruleForm.password" ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click=" submitForm('ruleForm')">主要按钮</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </template>
  
  <script>
  import md5 from 'md5'
  export default {
    data() {
      return {
        rules: {
            name: [
              { required: true, message: '请输入账号', trigger: 'blur' },
              { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
            ],
            password: [
              { required: true, message: '请输入密码', trigger: 'change' },
              {min:6 ,max:15,message:'gggg'}
            
            ],
        },
        ruleForm:{
           account:"newbee-admin6",
           password:"123456"
        },
  
      };
      
    },
    methods:{
      submitForm(formName) {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.loginfun()
              
            } else {
              console.log('error submit!!');
              return false;
            }
          });
        },
        
        async loginfun(){
          let result=await this.$http.post("/adminUser/login",{
            userName:this.ruleForm.account,
             passwordMd5: md5(this.ruleForm.password)
          })
          if(result.resultCode==200){
            sessionStorage.setItem("token",result.data);
            this.$message({
              message:"登录成功",
              type:'success'
            });
           this.$router.push("./index")
          }
          
            
   
  
        }
    }
    
    }
  </script>
  
  <style> scope.box {
    /* width: 300px;
     height: 350px;
     background-color: aquamarine; */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    /* align-items: center;  */
    /* margin: 0 auto; */
  }
  .login-box {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: aquamarine;
    width: 350px;
    height: 350px;
    padding: 0, 20px;
  
    box-sizing: border-box;
  }
  </style>
  
  
  
  
  
  
  
  
  
  
  